﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    string[] selectedRoleIdArray = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        selectedRoleIdArray = Request.Form.GetValues("chkRole");
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        gv.DataSource = selectedRoleIdArray;
        gv.DataBind();

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    http://topic.csdn.net/u/20090818/23/369a3442-ec63-4c28-b09e-58468dfe4dc8.html
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <asp:TreeView ID="tv" runat="server">
            <Nodes>
                <asp:TreeNode Text="角色管理" ShowCheckBox="true" SelectAction="Expand">
                    <asp:TreeNode SelectAction="None" Text="<input type='checkbox' name='chkRole' value='2' />添加角色<input type='checkbox' name='chkRole' value='3' />删除角色<input type='checkbox' name='chkRole' value='4' />更新角色">
                    </asp:TreeNode>
                </asp:TreeNode>
            </Nodes>
        </asp:TreeView>

        <script type="text/javascript">
            window.onload = function() {
                var strSelectedRoleIds = "<%= (selectedRoleIdArray == null ? "" : String.Join(",", selectedRoleIdArray)) + "," %>";
                var chkRoles = document.getElementsByName("chkRole");
                for (var i = 0; i < chkRoles.length; i++) {
                        chkRoles[i].checked = strSelectedRoleIds.indexOf(chkRoles[i].value) > -1
                }
            }
        </script>

        <asp:GridView ID="gv" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>
